<template>
  <div class="wrapper">
    <div class="boxes">
      <div v-for="key in state.num" :key="key" class="box">
        <div style="border: 2px solid rgb(235, 75, 75)">
          <img
              src="https://game-aesy.c5game.com/steam/730/13826c2a4017594a3a8f81dd82c43f3d.png?x-oss-process=image/resize,w_480,h_360"
              style="height: 70px"
          />
          <p>
            {{ key }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {reactive} from "vue";
import anime from "animejs/lib/anime.es.js";

const state = reactive({
  num: 40,
});

const open = () => {
  let xTrans = [];
  anime.set(".box", {
    translateX: function (el, i, l) {
      xTrans[i] = {x: i * 100};
      return i * 100;
    },
  });
  anime({
    targets: xTrans,
    duration: 6000, //走一周持续时间
    easing: "easeInOutQuad",
    x: `+=${state.num * 100}`,
    // loop: true,
    update: function (anim) {
      // console.log(anim)
      anime.set(".box", {
        translateX: function (el, i, l) {
          return xTrans[i].x % `${state.num * 100}`;
        },
      });
    },
  });
}

open()
</script>

<style>
body {
  margin: 0;
}

.wrapper {
  width: 700px;
  height: 100px;
  position: relative;
  margin: 40px auto 0;
  background: #ccc;
  overflow: hidden;
}

.box {
  width: 100px;
  height: 100px;
  position: absolute;
  background: red;
  font-size: 25px;
  line-height: 100px;
  text-align: center;
}

.box:nth-child(odd) {
  background: #f8f8f8;
}

.box:nth-child(even) {
  background: #eee;
}

.boxes {
  position: relative;
  left: -100px;
}
</style>
